/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.gui;

import java.util.List;
import javax.swing.table.DefaultTableModel;
import model.dao.DaoAluno;
import model.dominio.Aluno;

/**
 *
 * @author Teao
 */
public class GuiAlunoConsultar extends javax.swing.JPanel {
    
    private List<Aluno> lista;
    private List<Aluno> listaAluno;

    public GuiAlunoConsultar() {
        initComponents();
    }
    
    public void buscar() {
        Aluno c = new Aluno();
        if (!cpfAluno.getText().equals("   .   .   -  ")) {
            c.setCpf(cpfAluno.getText());
        }else if (!nomeAluno.getText().isEmpty()) {
            c.setNome(nomeAluno.getText());
        }
        lista = new DaoAluno().buscarAlunos(c);
        comboAluno.removeAll();

        
        for (Aluno aluno : lista) {
            comboAluno.addItem(aluno.getNome());
            
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        SelBusca = new javax.swing.ButtonGroup();
        jDialog1 = new javax.swing.JDialog();
        jDialog2 = new javax.swing.JDialog();
        buscarAluno = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        nomeAluno = new javax.swing.JTextField();
        cpfAluno = new javax.swing.JFormattedTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        comboAluno = new javax.swing.JComboBox();

        setLayout(null);

        buscarAluno.setIcon(new javax.swing.ImageIcon(getClass().getResource("/view/gui/icones/buscar.png"))); // NOI18N
        buscarAluno.setText("BUSCAR");
        buscarAluno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buscarAlunoActionPerformed(evt);
            }
        });
        add(buscarAluno);
        buscarAluno.setBounds(380, 50, 130, 70);

        jLabel1.setText("Selecione o metodo de busca:");
        add(jLabel1);
        jLabel1.setBounds(10, 10, 180, 20);
        add(nomeAluno);
        nomeAluno.setBounds(100, 40, 270, 40);

        try {
            cpfAluno.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("###.###.###-##")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }
        add(cpfAluno);
        cpfAluno.setBounds(100, 100, 270, 40);

        jLabel2.setText("CPF");
        add(jLabel2);
        jLabel2.setBounds(20, 110, 27, 17);

        jLabel3.setText("Nome");
        add(jLabel3);
        jLabel3.setBounds(20, 50, 42, 17);

        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Turma", "Disciplina", "Nota", "Falta", "Aprovação"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, true, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane3.setViewportView(jTable2);

        add(jScrollPane3);
        jScrollPane3.setBounds(170, 150, 360, 140);

        comboAluno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboAlunoActionPerformed(evt);
            }
        });
        add(comboAluno);
        comboAluno.setBounds(20, 200, 140, 30);
    }// </editor-fold>//GEN-END:initComponents

    private void buscarAlunoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buscarAlunoActionPerformed
       buscar();
       
    }//GEN-LAST:event_buscarAlunoActionPerformed

    private void comboAlunoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboAlunoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_comboAlunoActionPerformed
/**/
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup SelBusca;
    private javax.swing.JButton buscarAluno;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JComboBox comboAluno;
    private javax.swing.JFormattedTextField cpfAluno;
    private javax.swing.JDialog jDialog1;
    private javax.swing.JDialog jDialog2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTable jTable2;
    private javax.swing.JTextField nomeAluno;
    // End of variables declaration//GEN-END:variables
}

